package com.形为型模式.责任链模式;

/**
 * 领导 抽象处理者
 */
abstract class Leader {
    Leader leader;

    /**
     * 请假
     *
     * @param leaveDays
     */
    abstract void handleRequest(int leaveDays);

    public Leader getLeader() {
        return leader;
    }

    public void setLeader(Leader leader) {
        this.leader = leader;
    }
}
    /**
     * 班主任 具体处理者
     */
  class ClassAdviser extends Leader{
      @Override
      void handleRequest(int leaveDays) {
          if (leaveDays <=2){
              System.out.println("班主任批准了");
          }
          else{
              if(getLeader() != null){
                  getLeader().handleRequest(leaveDays);
              }
              else{
                  System.out.println("请不了");
              }
          }
      }
  }

    /**
     * 院长 具体处理者
     */
  class Dean extends Leader{
      @Override
      void handleRequest(int leaveDays) {
          if(leaveDays >7 && leaveDays <=10){
              System.out.println("系主任不批准，院长来批准了");
          }
          else{
              if(getLeader() != null){
                  getLeader().handleRequest(leaveDays);
              }
              else{
                  System.out.println("狗日的请不了");
              }
          }
      }
  }
  class DepartmentHead extends Leader{
      @Override
      void handleRequest(int leaveDays) {
          if(leaveDays >2 && leaveDays <=7){
              System.out.println("班主任不批准，系主任批准了");
          }
          else{
              if(getLeader() != null){
                  getLeader().handleRequest(leaveDays);
              }
              else{
                  System.out.println("狗日的请不了");
              }
          }
      }
  }

/**
 * 请假的责任链模式
 */
public class DutyHoliday {
    public static void main(String[] args) {
        Leader l1 = new ClassAdviser();
        Leader l2 = new DepartmentHead();
        Leader l3 = new Dean();
        l1.setLeader(l2);
        l2.setLeader(l3);
        l1.handleRequest(11);

    }

}
